<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" ref="listQuery" :model="listQuery" class="demo-form-inline">
        <el-form-item>
          <el-button v-waves type="success" icon="Search" @click="handleFilter">
            导出
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider class="el-divider--horizontal-margin" />
    <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        border
        fit
        show-summary
        highlight-current-row
        tooltip-effect="dark"
        style="width: 100%;"
        @sort-change="handleSortChange"
        @selection-change="handleSelectionChange"
    >
      {
      id: 'FA2022050001', // 单据号
      a1: '2022-08-29', // 到位日期
      a2: '[2022 538013 2120199 44010522000000000178712022 ', // 指标
      a3: '张三', // 项目类型
      a4: '[013001(危改所) 单位领导', // 部门
      a5: '200.00', // 到位金额
      a6: '0.00', // 摘要
      a66: '已审核', // 审核状态
      a7: '否', // 是否期初
      },
      <el-table-column align="center" type="index" label="序号" width="60px"/>
      <el-table-column align="center" label="单据号" fixed="left" prop="id" sortable
                       show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="到位日期" prop="a1" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="指标" prop="a2" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="项目类型" prop="a3" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="部门" prop="a4" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="到位金额" prop="a5" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="摘要" prop="a6" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="审核状态" prop="a66" sortable show-overflow-tooltip></el-table-column>
      <el-table-column align="center" label="是否期初" prop="a7" sortable show-overflow-tooltip></el-table-column>
    </el-table>
    <pagination v-model:total="total" v-model:page="listQuery.pageNum" v-model:limit="listQuery.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import {doGet, doPost, doPut, doDelete, doDownload} from '@/config/http'
import baseConfig from '@/mixins/baseConfig'
import {alertErrorMsg, customValidator, notifySuccess} from "@/config/common";

const emptyObj = {
  code: '',
  name: '',
  registrationName: '',
  department: '',
  time: '',
  isConstruction: '',
  identifying: '',
  examineName: '',
  id: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null,
  deleted: null,
  version: null
}

export default {
  name: 'Kpi',
  mixins: [baseConfig],
  data() {
    return {
      svc: 'icims-api',
      obj: Object.assign({}, emptyObj),
      routes: [],
      dialogVisible: false,
      dialogType: 'add',
      dialogTypeTitle: '新增',
      checkStrictly: false,
      defaultProps: {
        children: 'children',
        label: 'title'
      },
      tableKey: 0,
      list: [
        {
          id: 'FA2022050001', // 单据号
          a1: '2022-08-29', // 到位日期
          a2: '[2022 538013 2120199 44010522000000000178712022 ', // 指标
          a3: '张三', // 项目类型
          a4: '[013001(危改所) 单位领导', // 部门
          a5: '200.00', // 到位金额
          a6: '0.00', // 摘要
          a66: '已审核', // 审核状态
          a7: '否', // 是否期初
        },
        {
          id: 'FA2022050341', // 单据号
          a1: '2022-05-29', // 到位日期
          a2: '[2022 538013 2120199 44010522000000000178712022 ', // 指标
          a3: '张三', // 项目类型
          a4: '[013001(危改所) 单位领导', // 部门
          a5: '34500.00', // 到位金额
          a6: '0.00', // 摘要
          a66: '已审核', // 审核状态
          a7: '否', // 是否期初
        },
        {
          id: 'FA20452050341', // 单据号
          a1: '2022-05-29', // 到位日期
          a2: '[2022 538013 2120199 44010522000000000178712022 ', // 指标
          a3: '张三', // 项目类型
          a4: '[013001(危改所) 单位领导', // 部门
          a5: '45456.00', // 到位金额
          a6: '0.00', // 摘要
          a66: '未审核', // 审核状态
          a7: '否', // 是否期初
        },
      ],
      total: 0,
      listLoading: false,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        sortField: 'id',
        sortType: 'desc',
        level: null,
        code: null,
        name: null,
        weight: null,
        parentId: null,
        state: null,
        createTimeStart: null,
        createTimeEnd: null,
        updateTimeStart: null,
        updateTimeEnd: null,
      },
      selectionList: [],
      dialogFormVisible: false,
      dialogStatus: '',
      rules: {
        level: [{
          required: false,
          validator: customValidator,
          min: 1,
          max: 100,
          label: '指标级别',
          trigger: ['blur', 'change']
        }],
        code: [{
          required: false,
          validator: customValidator,
          min: 0,
          max: 50,
          label: '指标编号',
          trigger: ['blur', 'change']
        }],
        name: [{
          required: false,
          validator: customValidator,
          min: 1,
          max: 200,
          label: '指标名称',
          trigger: ['blur', 'change']
        }],
        weight: [{
          required: false,
          validator: customValidator,
          min: 0,
          max: 3,
          label: '优先级权重',
          trigger: ['blur', 'change']
        }],
        parentId: [{
          required: false,
          validator: customValidator,
          min: 0,
          max: 20,
          label: '上级指标ID',
          trigger: ['blur', 'change']
        }],
        state: [{
          required: false,
          validator: customValidator,
          min: 0,
          max: 20,
          label: '状态',
          trigger: ['blur', 'change']
        }],
      },
      kpiList: [],
    }
  },
  computed: {
    routesData() {
      return this.routes
    },
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
    },
    handleResetQuery() {
      this.resetForm("listQuery")
    },
    handleFilter() {
      this.listQuery.pageNum = 1
      this.getList()
    },
    handleModifyStatus(row, status) {
      this.$message({
        message: '操作Success',
        type: 'success'
      })
      row.status = status
    },
    handleSelectionChange(data) {
      this.selectionList = data
    },
    handleSortChange(data) {
      const {prop, order} = data
      this.listQuery.sortField = prop
      this.listQuery.sortType = order === 'ascending' ? 'asc' : 'desc'
      this.handleFilter()
    },
    handleEdit(row) {
      this.dialogType = 'edit'
      this.dialogTypeTitle = '编辑'
      this.dialogVisible = true
      this.checkStrictly = true
      this.obj = Object.assign({}, row)
    },
    handleView(row) {
      this.dialogType = 'view'
      this.dialogTypeTitle = '详情'
      this.dialogVisible = true
      this.checkStrictly = false
      this.obj = Object.assign({}, row)
    },
    handleAdd() {
      console.log('111111111111')
      this.goTargetByName('paymentContractEdit')
    },
    handleExport() {
      doDownload(this.svc, '/kpi/export', this.listQuery)
    },
    handleDelete(row) {
      this.$confirm('您确定删除么？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(_ => {
        doDelete(this.svc, '/kpi/' + row.id, {}).then(() => {
          notifySuccess('删除成功')
          this.getList()
          this.dialogVisible = false
        })
      })
    },
    async doConfirm(formName) {
      let v = await this.$refs[formName].validate().catch((err)=>{return err})
      if (v !== true) {
        alertErrorMsg('表单验证不通过，请检查数据。')
        return
      }
      if (this.dialogType === 'edit') {
        doPut(this.svc, '/kpi/modify', this.obj).then(() => {
          notifySuccess('修改成功')
          this.getList()
          this.dialogVisible = false
        })
      } else if (this.dialogType === 'add') {
        doPost(this.svc, '/kpi/add', this.obj).then(() => {
          notifySuccess('新增成功')
          this.getList()
          this.dialogVisible = false
        })
      }
    },
  }
}
</script>
